package com.xiaoshuidi.cloud.module.rooms.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.iot.vo.RoomSdiotAssocationVo;
import com.xiaoshuidi.cloud.module.rooms.mapper.RoomSdiotAssociationMapper;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomSdiotAssociation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @BelongsProject: lease-module-rooms
 * @BelongsPackage: com.xiaoshuidi.cloud.module.rooms.repository
 * @Author: James
 * @CreateTime: 2023-05-29  18:37
 * @Description: TODO
 * @Version: 1.0
 */
@Component
public class IotRoomAassociationRepository extends ServiceImpl<RoomSdiotAssociationMapper, RoomSdiotAssociation> {
    @Autowired
    private RoomSdiotAssociationMapper roomSdiotAssociationMapper;

    public int removeSdiotAssociation(Long waringId) {
        QueryWrapper<RoomSdiotAssociation> wrapper = new QueryWrapper();
        wrapper.eq("waring_id", waringId);
        return roomSdiotAssociationMapper.delete(wrapper);
    }

    public List<RoomSdiotAssocationVo> getWaringInfo(Long waringId) {
        QueryWrapper<RoomSdiotAssociation> wrapper = new QueryWrapper();
        wrapper.eq("waring_id", waringId)
                .eq("rsa.deleted", false);
        List<RoomSdiotAssocationVo> listRoomId = roomSdiotAssociationMapper.getWaringInfo(wrapper);
        return listRoomId;
    }
}
